package twentytwentyone_3;

import java.util.Arrays;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2021-03-15 13:17
 * @Modified By:
 */
public class ArrayPairSum_561 {
    public static void main(String[] args){
        int[] nums = new int[]{1,4,3,2};
        System.out.println(arrayPairSun(nums));
    }

    public static int arrayPairSun(int[] nums){
        Arrays.sort(nums);
        int sum = 0;
        for (int i = 0; i < nums.length; i+=2) {
            sum += Math.min(nums[i],nums[i + 1]);
        }
        return sum;
    }
}
